package com.it.security.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Enumeration;

@Configuration
@Slf4j
public class JwtLoginfilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        log.info("每一次请求都经过这里");
        String cookie = httpServletRequest.getHeader("Cookie");
        String host = httpServletRequest.getHeader("Host");
        HttpSession session = httpServletRequest.getSession();
        String requestedSessionId = httpServletRequest.getRequestedSessionId();

        Enumeration attributeNames = session.getAttributeNames();
        while (attributeNames.hasMoreElements()) {
            System.out.println(attributeNames.nextElement());
        }
        // 获取用户名
        Object user = session.getAttribute("user");
        System.out.println("user:"+user);


        log.info("获取的cookie："+cookie);
        log.info("获取的主机号："+host);
        log.info("session"+session.getServletContext());
        log.info("requestedSessionId:"+requestedSessionId);
        filterChain.doFilter(httpServletRequest,httpServletResponse);
    }
}
